﻿namespace Yom.WebService
{
    using System;
    using System.Web.UI;
    using Yom.Common;
    using Yom.WebService.Default;

    public class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (System.IO.Directory.Exists(Factory.MapPath("~/Installer")))
            {
                Response.Clear();
                Response.Write("安装文件夹依然存在,若您还没有进行安装,请点击<a href=\"Installer/Index.htm\">这里</a>进行安装,否则请将其删除!");
                Response.End();
            }

            if (!Fso.Exists(Factory.MapPath("~/Index." + SiteLoad.Scheme.Ext)))
            {
                Response.Clear();
                Response.Write("首页静态文件并不存在, 请登录后台\"系统设置\"中\"清理服务器缓存\"生成首页静态文件!");
                Response.End();
            }

            string Action = Factory.Request("Action");

            switch (Action)
            {
                case "Search":
                    Response.Write(new DefaultSearch().OutWrite());
                    break;
                case "Notice":
                    Response.Write(new DefaultNotice().OutWrite());
                    break;
                case "List":
                    Response.Write(new DefaultList().OutWrite());
                    break;
                case "Click":
                    string ID = Factory.Request("ID");
                    if (!string.IsNullOrEmpty(ID))
                    {
                        new Yom.Data.Comic().Visit(ID.ToLong());
                    }
                    Response.Clear();
                    Response.Write("var click=0;");
                    Response.End();
                    break;
                case "Visit":
                    string sID = Factory.Request("ID");
                    string click = "0";
                    if (!string.IsNullOrEmpty(sID))
                    {
                        click = new Yom.Data.Comic().GetModel(sID.ToLong()).Visit.ToString();
                    }
                    Response.Clear();
                    Response.Write("document.write('" + click + "');");
                    Response.End();
                    break;
                default:
                    break;
            }
        }
    }
}